import wepy from 'wepy'
export default class extends wepy.mixin {
	data = {
		// 分页页数
		pageIndex: '1',
		// 分页大小
		pageSize: '10',
		// 分类数据
		getGoodsListInfo: [],
		// 商品列表的总数
		isLoading: false,
		total: 10000,
		// 数据加载完，控制显示与隐藏
		isOver: false,
		banwei: '',
		// 搜索关键字
		searchli: '',
	}
	methods = {
		//点击搜索跳转到的页面
		search() {
			wepy.navigateTo({
				url: '../../pages/Search/search',
			})
		},
		// 点击商品跳转
		goGoodsDatils(id) {
			console.log('商品详情', id)
			wepy.navigateTo({
				url: '../../pages/goodsDatils/gooddatils?id=' + id,
			})
		},
		handle() {
			console.log('添加到购物车')
			wepy.baseToast('已添加到购物车')
		},
		// 点击跳转到商品列表
		goGoodslist(type, linkUrl, id) {
			//type="0";        //跳转方式 0 不跳转  1链接跳转  2内容跳转  3商品跳转 4店铺跳转 5活动跳转  6商品类型跳转 7秒杀跳转
			console.log(type, linkUrl, id)
			if (type == 0) {
				
			} else if (type == 1) {
				//链接跳转
				wepy.navigateTo({
					url: '../../pages/lianjie/lianjie?id=' + id + '&index=' + 1,
				})
			} else if (type == 2) {
				//内容跳转
				wepy.navigateTo({
					url: '../../pages/edittion/edittion?id=' + id + '&index=' + 2,
				})
			} else if (type == 3) {
				//商品跳转
				wepy.navigateTo({
					url: '../../pages/goodsDatils/gooddatils?id=' + linkUrl + '&index=' + 3,
				})
			} else if (type == 4) {
				
			} else if (type == 5) {
				//活动跳转
				wepy.navigateTo({
					url: '../../pages/manJian/manjian?MJId=' + linkUrl + '&index=' + 5,
				})
			} else if (type == 6) {
				//商品类型跳转
				wepy.navigateTo({
					url: '../../pages/goodsList/goodslist?categoryId=' + linkUrl + '&index=' + 6,
				})
			} else if (type == 7) {
				//秒杀
				wepy.navigateTo({
					url: '../../pages/Time/time?id=' + linkUrl + '&index=' + 7,
				})
			} else if (type == 8) {
				//专区
				wepy.navigateTo({
					url: '../../pages/Advice/advice?id=' + linkUrl + '&index=' + 8,
				})
			} else if (type == 9) {
				//卡券
				wepy.navigateTo({
					url: '../../pages/kaquanlist/kaquanlist',
				})
			} else if (type == 10) {
				//卡券详情
				wepy.navigateTo({
					url: '../../pages/kadetail/kadetail?id='+linkUrl,
				})
			}
		},
	}
	onLoad() {
		this.getGoodsListInfo=[];
		this.pageIndex='1';
		this.getGoodsList()
	}
	onShow() {
		this.advertising()
		this.searchInfo()
	}
	async getGoodsList(callback) {
		// 发起请求，先将值重置为true
		this.isLoading = true
		const res = await wepy.post('baseRest/getGoodsList', {
			pageIndex: this.pageIndex,
			pageSize: this.pageSize,
			isPoint:"0"
		})
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		this.getGoodsListInfo = [...this.getGoodsListInfo, ...res.data.data]
		// 赋值完，再重置为false
		this.isLoading = false
		this.$apply()
		callback && callback()
		console.log(this.getGoodsListInfo)
	}
	//广告版位
	async advertising() {
		const res = await wepy.post('baseRest/getAdCmsList', {
			// cateType: '1',
			parentId:"m5iZG",
		})
		if (res.statusCode != 200) {
			return wepy.noToast('获取数据失败')
		}
		console.log(res, 'lllllllllll')
		this.banwei = res.data.data
		this.$apply()
	}
	// 获取搜索
	async searchInfo() {
		const {
			data: res
		} = await wepy.post('baseRest/getDictionaryList', {
			parentId: '105',
		})
		console.log('搜索数据', res)
		if (res.state != 1) {
			return wepy.noToast('网络异常')
		}
		this.searchli = res.data[0].name
		this.$apply()
	}
	onReachBottom() {
		console.log('已触底')
		//判断数据是否正在请求中
		if (this.isLoading) {
			return
		}
		if (parseInt(this.pageIndex) * parseInt(this.pageSize) >= this.total) {
			this.isOver = true
			return
		}
		let num = parseInt(this.pageIndex)
		num++
		this.pageIndex = num.toString()
		this.getGoodsList()
	}
}
